const mongoose = require('mongoose');
const Challenge = require('../models/Challenge');
require('dotenv').config();

const challenges = [
  {
    title: "零塑料周",
    description: "一周内不使用任何一次性塑料制品",
    points: 100,
    duration: "7天",
    category: "日常生活",
    difficulty: "中等",
    tasks: [
      { text: "自带购物袋", points: 20 },
      { text: "使用可重复使用的水杯", points: 20 },
      { text: "拒绝一次性餐具", points: 30 },
      { text: "选择无包装商品", points: 30 }
    ]
  },
  {
    title: "绿色出行",
    description: "连续5天使用公共交通或步行上下班",
    points: 80,
    duration: "5天",
    category: "交通",
    difficulty: "简单",
    tasks: [
      { text: "步行或骑车上班", points: 30 },
      { text: "使用公共交通", points: 20 },
      { text: "与他人拼车", points: 30 }
    ]
  },
  {
    title: "节能达人",
    description: "将本月用电量较上月减少10%",
    points: 150,
    duration: "30天",
    category: "节能减排",
    difficulty: "困难",
    tasks: [
      { text: "记录用电数据", points: 30 },
      { text: "使用节能电器", points: 40 },
      { text: "控制空调温度", points: 40 },
      { text: "养成随手关灯习惯", points: 40 }
    ]
  }
];

async function seedDatabase() {
  try {
    await mongoose.connect(process.env.MONGODB_URI);
    console.log('Connected to MongoDB');

    // 清除现有数据
    await Challenge.deleteMany({});
    console.log('Cleared existing challenges');

    // 插入新数据
    const result = await Challenge.insertMany(challenges);
    console.log(`Added ${result.length} challenges`);

    mongoose.connection.close();
  } catch (error) {
    console.error('Error seeding database:', error);
    process.exit(1);
  }
}

seedDatabase(); 